﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Design;
using Zhp.Model.Common;
using Zhp.Model.Design;

namespace Zhp.Api.Controllers.Design
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Design)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Design, Name = "列表管理", Order = 3, RouterName = "designlist", WebFilePath = "design/designList/index", Icon = "list-setting")]

    public class DesignListController : ControllerBase
    {
        private IDesignListService _designListService;
        public DesignListController(IDesignListService designListService)
        {
            _designListService = designListService;
        }

        [HttpPost]
        [SeedList("设计列表", "列表管理", ApiGroupEnum.Design, ["/api/designform/select", "/api/designform/QueryFieldSelect", "/api/designform/QueryFormFieldConfig"])]
        public async Task<PageRet<DesignListModel>> Query(DesignListQuery p)
        {
            var list = await _designListService.Query(p);
            return new PageRet<DesignListModel>
            {
                DataList = list,
                TotalCount = p.TotalCount,
            };
        }

        [HttpPost]
        [SeedButton("新增", "设计列表", "列表管理", ApiGroupEnum.Design)]
        public async Task<bool> Create(DesignListEdit p)
        {
            return await _designListService.Create(p);
        }

        [HttpPut]
        [SeedButton("修改", "设计列表", "列表管理", ApiGroupEnum.Design)]
        public async Task<bool> Update(DesignListEdit p)
        {
            return await _designListService.Update(p);
        }

        [HttpDelete("{id}")]
        [SeedButton("删除", "设计列表", "列表管理", ApiGroupEnum.Design)]
        public async Task<bool> Delete(long id)
        {
            return await _designListService.Delete(id);
        }

        [HttpGet("{id}")]
        [SeedButton("详情", "设计列表", "列表管理", ApiGroupEnum.Design)]
        public async Task<DesignListEdit> Details(long id)
        {
            return await _designListService.Details(id);
        }
    }
}
